home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5869 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  53 lines

  1. Newsgroups: comp.lang.c
  2. Path: cs.mun.ca!sjt
  3. From: sjt@cs.mun.ca (Stephen J. Tremblett)
  4. Subject: Re: Character String --> Integer
  5. Message-ID: <1996Feb20.185030.22691@cs.mun.ca>
  6. Sender: usenet@cs.mun.ca (NNTP server account)
  7. Organization: CS Dept., Memorial University of Newfoundland
  8. X-Newsreader: TIN [version 1.2 PL2]
  9. References: <4fb0ga$lsa@remus.rutgers.edu> <4ffr4e$4ji@madeline.INS.CWRU.Edu>
  10. Date: Tue, 20 Feb 1996 18:50:30 GMT
  11.  
  12.  
  13.  
  14.  
  15. I did this very recently in an assig.
  16. A char variable is just an int interpreted into the values of the ascii
  17. table.  A char variable - 48 (ascii for 0) will result in the integer
  18. value of that digit.
  19.  
  20.  
  21. Steve T.
  22.  
  23. Michael A. Balfour (mab22@po.CWRU.Edu) wrote:
  24.  
  25. : In a previous article, wempa@remus.rutgers.edu (Force Of Nature) says:
  26.  
  27. : >Is there an easy way to convert a character string such as '2425' to the
  28. : >integer 2425 ???  The only way I can think of is to pick off characters 
  29. : >one at a time and use switch statements to determine the value (0-9) and
  30. : >then multiply by the correct power of 10.  Is there an easier way to do
  31. : >this ???????
  32. : >
  33. : >
  34.  
  35. : Just to throw a tiny spin on the discussion, if you don't know if the
  36. : character set for the string matches the native character set (i.e.
  37. : EBCDIC string on an ASCII machine), you can't use the standard library
  38. : functions.  But rather than use a switch statement, you can LOGICAL AND
  39. : each character with 0x0F.  It'll save you a little time anyways.
  40.  
  41. : Mike Balfour
  42.  
  43. : -- 
  44. : ----------------------------------+--------------------------------
  45. : Mike Balfour, Partner             | BS/MS Candidate - ECMP
  46. : Overload Engineering              | Case Western Reserve University
  47. : "New Ideas for a Brighter Future" | Cleveland, OH
  48. -- 
  49. I am far to young to feel so old
  50. And far too tired to care
  51. But I took down twenty bastards before they left me lying there
  52.  - The Lowest of the Low
  53.